<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>调用函数</title>
</head>

<body>
  <script>
    // 方法调用
    function f() {
      return { m() { return 2 } }
    }
    c = f().m()
    console.log(c);




    let o = {
      m: function () {
        // const f = (() => {
        //   console.log(this);
        //   // 如果是箭头函数则返回true
        //   console.log(this === o);
        //   this === o
        // })

        // let f = (function f() {
        //   // 如果是函数表达式则会返回false 需要bind（）才会返回true
        //   console.log(this === o);
        //   this === o
        // }).bind(this)

        // 嵌套函数
        function f() {
          //嵌套函数里this指向全局。严格模式指向undefined
          console.log(this);
          console.log(this === o);
          console.log(self === o);
        }
        console.log(this);
        let self = this;
        this === o
        console.log(this === o);
        f();
      }
    }
    o.m()

  </script>
</body>

</html>